package com.hula.onion.book.server.spider.platforms.ppmoney;

import com.alibaba.fastjson.JSONObject;
import com.hula.onion.book.server.common.CommonResponse;
import com.hula.onion.book.server.common.LoginForm;
import com.hula.onion.book.server.config.ResponseStatusEnum;
import com.hula.onion.book.server.model.AccountInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by work on 2018/1/21.
 */
@Component
public class PPmoneySpiderHelper {
    public Map<String, Object> installRequestParams(LoginForm loginForm) {
        Map<String, Object> map = new HashMap<>(5);
        map.put("Phone", loginForm.getUserName());
        map.put("Password", loginForm.getPassword());
        return map;
    }

    /**
     * 解析账户余额
     *
     * @param accountStr
     * @return
     */
    public CommonResponse parseAccountBalance(String accountStr) {
        if (StringUtils.isEmpty(accountStr)) {
            return new CommonResponse(ResponseStatusEnum.QUERY_FAIL);
        }
        JSONObject jsonObject = (JSONObject) JSONObject.parse(accountStr);
        AccountInfo accountInfo=new AccountInfo();
        if (jsonObject.getBigDecimal("Amount")!=null) {
            accountInfo.setAmount(jsonObject.getBigDecimal("Amount"));
        }
        return new CommonResponse(accountInfo);
    }
}
